<html>
<head><meta charset="utf-8"><title>Forced unwinding · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html">Forced unwinding</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="188937928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188937928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188937928">(Feb 24 2020 at 15:51)</a>:</h4>
<p>I've been reading a bit of glibc source code and I think I now have a better idea of how forced unwinding actually works. Basically in glibc, forced unwind works by try to unwind normally as many frames as possible while running destructors. Once it reaches a frame with no unwind info, it skips all remaining frames by using a simply longjmp.</p>



<a name="188937958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188937958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188937958">(Feb 24 2020 at 15:51)</a>:</h4>
<p>This is how forced unwind can work with both <code>-fexceptions</code> and <code>-fno-exceptions</code>.</p>



<a name="188938111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188938111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188938111">(Feb 24 2020 at 15:53)</a>:</h4>
<p>As such I would like to revise my previous position that unwinding through <code>nounwind</code> is not UB. Keep in mind that with <code>-C panic=abort</code> we often don't even have unwinding tables, so unwinding most likely will not work.</p>



<a name="188938207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188938207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188938207">(Feb 24 2020 at 15:54)</a>:</h4>
<p>In terms of how it affects the proposals, it just turns non-forced unwinding from <code>unwind</code> to <code>UB</code> in the table. I don't think this change has any effect on the pros/cons that are listed.</p>



<a name="188938445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188938445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188938445">(Feb 24 2020 at 15:57)</a>:</h4>
<p>Interesting. Thank you for looking into that.</p>



<a name="188962247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188962247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188962247">(Feb 24 2020 at 20:23)</a>:</h4>
<p>The new "forced unwinding" description is a bit confusing to me. First,  is it not actually true that <code>catch (...) { }</code> will cause the program to abort on forced-unwind? Second, are frames that "do not have unwinding support" just frames marked w/ <code>nounwind</code>?</p>



<a name="188969229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188969229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188969229">(Feb 24 2020 at 21:42)</a>:</h4>
<p>There's also frames with no unwinding tables.</p>



<a name="188969241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188969241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188969241">(Feb 24 2020 at 21:42)</a>:</h4>
<p>That's the main issue here.</p>



<a name="188969394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188969394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188969394">(Feb 24 2020 at 21:44)</a>:</h4>
<p>A normal unwind will just abort if it finds a frame with no unwind info. But pthread uses a hack and performs a longjmp when it reaches such a frame.</p>



<a name="188969421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188969421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188969421">(Feb 24 2020 at 21:44)</a>:</h4>
<p><a href="https://github.com/bminor/glibc/blob/master/nptl/unwind.c#L54" target="_blank" title="https://github.com/bminor/glibc/blob/master/nptl/unwind.c#L54">https://github.com/bminor/glibc/blob/master/nptl/unwind.c#L54</a></p>



<a name="188972236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188972236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188972236">(Feb 24 2020 at 22:16)</a>:</h4>
<p>So that would apply in <code>panic=abort</code> for both "C" and "C unwind" in all three proposals, and in <code>panic=unwind</code> for "C" with proposals 1 &amp; 2?</p>



<a name="188976268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188976268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188976268">(Feb 24 2020 at 23:10)</a>:</h4>
<p>Yes, sort of. Except "C unwind" under <code>panic=abort</code> will need to have unwinding tables since it needs to catch foreign exceptions and abort.</p>



<a name="188976296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188976296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188976296">(Feb 24 2020 at 23:10)</a>:</h4>
<p>"C" under <code>panic=abort</code> will not have unwinding tables.</p>



<a name="188976345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188976345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188976345">(Feb 24 2020 at 23:11)</a>:</h4>
<p>"C" under <code>panic=unwind</code> in proposal 1&amp;2 <em>does</em> have unwinding tables, but it is declared <code>nounwind</code> so LLVM will optimize destructors away.</p>



<a name="188977069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188977069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188977069">(Feb 24 2020 at 23:21)</a>:</h4>
<p>Sorry I missed your first question.</p>
<blockquote>
<p>First, is it not actually true that catch (...) { } will cause the program to abort on forced-unwind?</p>
</blockquote>
<p>Yes it is technically true but I don't think it is very relevant to this discussion so I removed it. Rust has no mechanism for catching foreign exceptions (<code>catch_unwind</code> only catches Rust panics).</p>



<a name="188980368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188980368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188980368">(Feb 25 2020 at 00:17)</a>:</h4>
<blockquote>
<p>catch_unwind only catches Rust panics</p>
</blockquote>
<p>Hm, that's actually probably worth mentioning in the blog post, come to think of it!</p>



<a name="188994127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188994127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188994127">(Feb 25 2020 at 06:07)</a>:</h4>
<p>I believe there was recently a PR to make catch_unwind catch foreign exceptions too.</p>



<a name="188998870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/188998870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#188998870">(Feb 25 2020 at 08:06)</a>:</h4>
<p>I made a PR to make catch_unwind not segfault on foreign exceptions, is that what you're referring to? They're still not caught though.</p>



<a name="189009955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Forced%20unwinding/near/189009955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Forced.20unwinding.html#189009955">(Feb 25 2020 at 11:08)</a>:</h4>
<p>Yes, I was refering to <a href="https://github.com/rust-lang/rust/issues/65646" target="_blank" title="https://github.com/rust-lang/rust/issues/65646">#65646</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>